/* Copyright 2007 Gearbox Software - http://www.gearboxsoft.com
 
 Licensed under the Apache License, Version 2.0 (the "License");
 you may not use this file except in compliance with the License.
 You may obtain a copy of the License at
 
     http:www.apache.org/licenses/LICENSE-2.0
 
 Unless required by applicable law or agreed to in writing, software
 distributed under the License is distributed on an "AS IS" BASIS,
 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 See the License for the specific language governing permissions and
 limitations under the License.*/
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

namespace GearBlog.Web.Helpers
{
	using Castle.MonoRail.Framework;
	using Castle.MonoRail.Framework.Helpers;

	public class IncludeHelper:AbstractHelper
	{

		public static string JavaScript(string path, IRailsEngineContext context)
		{
			path = GetPath(path, "js", context);

			return string.Format("<script type=\"text/javascript\" src=\"{0}\" language=\"javascript\"></script>", path);
		}
		public string JavaScript(string path)
		{
			return JavaScript(path, CurrentContext);
		}

		public static string GetPath(string path, string extension, IRailsEngineContext context)
		{
			if (path.Substring(path.Length - 4, 3) != "." + extension && !string.IsNullOrEmpty(extension))
				path += "." + extension;
			if (path[0] == '/')
				path = context.ApplicationPath + path;
			return path;
		}
		public string GetPath(string path, string extension)
		{
			return GetPath(path, extension, CurrentContext);
		}

		public string JS(string path)
		{
			return JavaScript(path);
		}
		public string CSS(string path)
		{
			path = GetPath(path, "css");
			return string.Format("<link rel=\"stylesheet\" type=\"text/css\" href=\"{0}\"/>", path);
		}

		
	}
}
